package com.itheima.service.impl;

import com.itheima.dao.AccountDao;
import com.itheima.domain.Account;
import com.itheima.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

/**
 * 业务层意思
 *
 */
@Service("accountService")
@Transactional(readOnly = false)
/**
 * Propagation propagation() 事务传播行为
 *
 * Isolation isolation() 事务隔离级别 不要修改它 默认就是对的
 *
 * int timeout() 超时 默认-1  永不超时
 *
 * Class<? extends Throwable>[] rollbackFor() 默认情况 遇到runtimeexception的情况就会回滚
 *
 * Class<? extends Throwable>[] noRollbackFor()
 */

public class AccountServiceImpl implements AccountService {
    @Autowired
    private AccountDao accountDao;



    @Override
    @SuppressWarnings("all")
    @Transactional(rollbackFor = ArithmeticException.class)
    public void transfer(int from, int to, double money) {

        accountDao.add(to,money);
        try {
            int i=5/0;
        }catch (Exception e){
            throw new RuntimeException("哈哈哈啊哦我是一个异常");
        }

        accountDao.sub(from,money);
        //调用别人写的方法


    }


    @Override
    @Transactional
    public void delete(int id) {
        accountDao.delete(id);
    }

    @Override
    @Transactional
    public void add(Account account) {

        accountDao.save(account);

    }

    @Override
    @Transactional(readOnly = true)
    public Account findById(int id) {


        return accountDao.findById(id);
    }

    public void  xxx(){
        System.out.println("我是该类中一个辅助方法~~~~");
    }
}
